<?php $this->load->view('layout/header'); ?>
<div id="container">
    <!--查询表单开始-->
    <div id="DivQuery">
        <div id="floatBoxBg" style="filter: alpha(opacity=0); opacity: 0;">
        </div>
        <div id="floatBox" class="floatBox">
            <div id="drag" class="title" onmousedown="DragDialog()">
                <h4>
                    查询</h4>
                <span>关闭</span></div>
            <div class="content">
                <form action="<?php echo b_url('config/syslimit')?>" method="post">
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_query">
                        <tr class="table_query_row">
                            <td style="width: 15%" align="right">地区名称：</td>
                            <td><input name="limitname" type="text" id="txtLimitName" /></td>
                        </tr>
                        <tr class="table_query_btn">
                            <td align="right" style="width: 15%"></td>
                            <td>
                                <input type="submit" name="btnQuery" value="查询" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;btnQuery&quot;, &quot;&quot;, false, &quot;&quot;, &quot;SysLimit.aspx&quot;, false, false))" id="btnQuery" />
                                <input type="button" value="返回" onclick="javascript:HiddenSearchDialog();" />
                            </td>
                            <td align="right" style="width: 15%"></td>
                            <td></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_op">
        <tr>
            <td>
                操作选项：
                <a href="<?php echo b_url('config/area_add')?>">添加地区</a>
                <a onclick="javascript:return checkEdit(this);" name="areaid" href="javascript:;)" src="<?php echo b_url('config/area_add/');?>">修改地区</a>
                <a onclick="javascript:return checkDel(this);" name="areaid" href="javascript:;)" src="<?php echo b_url('config/delete_info/syslimit/syslimitid/syslimit/')?>">删除地区</a>
                <a onclick="javascript:return checkOperate(this);" name="areaid" href="javascript:;" src="<?php echo b_url('config/edit_close/syslimit/syslimitid/syslimit/0/')?>">批量开放</a>
                <a onclick="javascript:return checkOperate(this);" name="areaid" href="javascript:;" src="<?php echo b_url('config/edit_close/syslimit/syslimitid/syslimit/1/')?>">批量关闭</a>
                <a href="javascript:SearchDialog()">查询地区</a>
            </td>
        </tr>
    </table>
    <!--操作选项结束-->
    <!--列表开始-->
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_list" id="TbList">
        <tr class="table_list_title">
            <td style="width: 2%">
                <input type="checkbox" name="checkbox" value="checkbox" onclick="javascript:check_all(this,'areaid')" />
            </td>
            <td style="width: 10%">
                编号
            </td>
            <td style="width: 10%">
                地区名称
            </td>
            <td style="width: 10%">
                所属地区
            </td>
            <td style="width: 10%">
                排序号
            </td>
            <td style="width: 10%">
                创建人
            </td>
            <td style="width: 10%">
                创建时间
            </td>
            <td style="width: 10%">
                状态
            </td>
            <td style="width: 10%">
                操作
            </td>
        </tr>
        <?php foreach($list as $k=>$v) : ?>
            <tr class="table_list_row_normal parent<?php echo $v['areaid'];?>">
                <td style="width: 2%">
                    <input name="areaid" type="checkbox" id="areaid" value="<?php echo $v['areaid']?>"  />
                </td>
                <td style="width: 10%">
                    <?php echo $v['areaid']?>
                </td>
                <td style="width: 10%">
                    <?php echo $v['areaname']?>
                </td>
                <td style="width: 10%">
                    <?php echo $v['parentname']?>
                </td>
                <td style="width: 10%">
                    <?php echo $v['listid']?>
                </td>
                <td style="width: 10%">
                    <?php echo $v['adminname']?>
                </td>
                <td style="width: 10%">
                    <?php echo $v['addtime']?>
                </td>
                <td style="width: 10%">
                    <?php
                    if($v['isclose'] == 0){
                        echo '开放';
                    }elseif($v['isclose'] == 1){
                        echo '<font color="red">关闭</font>';
                    }
                    ?>
                </td>
                <td style="width: 10%">
                    <?php if($v['childnum'] != 0){ ?>
                        <span class="change_btn" style="cursor: pointer;color:blue;" onclick="explode_this(<?php echo $v['areaid']; ?>)">展开</span>
                    <?php } ?>
                    <a href="<?php echo b_url('config/area_child_add/'.$v['areaid'])?>">添加子地区</a>
                </td>
            </tr>
        <?php endforeach ; ?>
    </table>
    <!--列表结束-->
</div>
<?php $this->load->view('layout/footer'); ?>
<script type="text/javascript">

    function check_all(obj, name){ //选择所有记录,所有行高亮
        if (obj.checked == true) {
            $('input[name="' + name + '"]').attr('checked', true);
            $('#TbList tr').attr('class', 'table_list_row_selected');
        } else {
            $('input[name="' + name + '"]').removeAttr('checked');
            $('#TbList tr:odd').attr('class', 'table_list_row_normal');
            $('#TbList tr:even').attr('class', 'table_list_row_alert');
        }
        $('#TbList tr:first').attr('class', 'table_list_title');
    }

    function explode_this(id){
        $.ajax({
            type: "GET",
            url: "http://"+window.location.host+"/admin.php/config/ajaxArea/"+id,
            dataType: "json",
            success: function(data){
                var myJson = eval(data);
                if(myJson.length>0){
                    var html = '';
                    for(var i=0;i<myJson.length;i++){
                        html += '<tr class="table_list_row_normal parent'+myJson[i].areaid+' son'+id+'">';
                        html += '<td style="width: 2%"><input name="areaid" id="areaid" type="checkbox"  value="'+myJson[i].areaid+'" /></td>'+
                            '<td style="width: 10%">'+myJson[i].areaid+'</td>'+
                            '<td style="width: 10%">'+myJson[i].areaname+'</td>'+
                            '<td style="width: 10%">'+myJson[i].parentname+'</td>'+
                            '<td style="width: 10%">'+myJson[i].listid+'</td>'+
                            '<td style="width: 10%">'+myJson[i].adminname+'</td>'+
                            '<td style="width: 10%">'+myJson[i].addtime+'</td>';
                        if(myJson[i].isclose == 0){
                            html += '<td style="width: 10%">开放</td>';
                        }else{
                            html += '<td style="width: 10%">关闭</td>';
                        }
                        html += '<td>';
                        if(myJson[i].childnum != 0){
                            html += '<span class="change_btn" style="cursor: pointer;color:blue;" onclick="explode_this('+myJson[i].areaid+')">展开</span>';
                        }
                        html += '<a href="/admin.php/config/area_child_add/'+myJson[i].areaid+'">添加子地区</a></td></tr>';
                    }
                    $('.parent'+id).after(html);
                    $('.parent'+id+' .change_btn').attr('onclick','im_explode_this('+id+')');
                    $('.parent'+id+' .change_btn').text('收起');
                }
            }
        });
    }

    function im_explode_this(id){

        $.ajax({
            type: "GET",
            url: "http://"+window.location.host+"/admin.php/config/ajax_implore/"+id,
            dataType: "html",
            success: function(data){
                var myJson = eval(data);
                for(var i=0;i<myJson.length;i++){
                    if($('.parent'+myJson[i]).val() == ''){
                        $('.parent'+myJson[i]).remove();
                    }
                }
            }
        });

        $('.parent'+id+' .change_btn').attr('onclick','explode_this('+id+')');
        $('.parent'+id+' .change_btn').text('展开');
    }

</script>